'use strict';

const request = require('request');
const uploadFile = require('../lib/function/qiniu');

module.exports = {
  async uploadFile (url) {
    const fileStream = await request(url);

    const accessKey = this.app.config.qiniu.accessKey;
    const secretKey = this.app.config.qiniu.secretKey;
    const bucket = this.app.config.qiniu.bucket.subImg.name;
    const zone = this.app.config.qiniu.bucket.subImg.zone;
    const uploadResult = await uploadFile(fileStream, accessKey, secretKey, bucket, zone);
    return uploadResult;
  }
};
